home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_11 / 2n11047a < prev    next >
Text File  |  1991-08-05  |  1KB  |  53 lines

  1. /*  Windows Initialization Files -- sample source code Listing 3
  2.  *  Kevin H. Carlson  8/07/91
  3.  */
  4.  
  5. /*  The WIN.INI file contains a section named [windows] that has a
  6.  *  key called device.  For the purpose of this example, that line
  7.  *  is given to be: 
  8.  *
  9.  *  [windows]
  10.  *  device=PostScript Printer,PSCRIPT,LPT1:
  11.  *
  12.  */
  13.  
  14.  
  15. .
  16. .
  17. .
  18.  
  19. HDC       hPrinterDC;
  20. char      deviceStr[80];
  21. int       resultLength;
  22. LPSTR     driverName;
  23. LPSTR     deviceName = NULL;
  24. LPSTR     output = NULL;
  25.  
  26. // create printer DC
  27. resultLength = GetProfileString((LPSTR)"windows", (LPSTR)"device",
  28.                     "", deviceStr, sizeof(deviceStr));
  29.  
  30. /* replace commas with Nulls and set parameter pointers */
  31. driverName = (LPSTR) deviceStr;
  32. for(i = 0; i < resultLength; i++)
  33.      {
  34.      if(deviceStr[i] == ',')
  35.           {
  36.           deviceStr[i] = '\0';
  37.           if(!deviceName)
  38.                deviceName = &deviceStr[i+1];
  39.           else
  40.                {
  41.                output= &deviceStr[i+1];
  42.                break;
  43.                }
  44.                 }
  45.         }
  46.  
  47. /* create printer DC */
  48. hPrinterDC = CreateDC(deviceName, driverName, output, NULL);
  49.  
  50. .
  51. .
  52. .
  53.